import Taro, { ENV_TYPE } from '@tarojs/taro';
import { FC, ReactNode } from 'react';
import { BrowserRouter, Link, MemoryRouter, Route, RouteObject, Routes } from 'react-router-dom';
const isH5 = Taro.getEnv() === ENV_TYPE.WEB;
const RouterFragment: FC<{ children: ReactNode }> = ({ children }) => {
    if (isH5) return <BrowserRouter>{children}</BrowserRouter>;
    return <MemoryRouter>{children}</MemoryRouter>;
};
export const CrossRouterRender = ({ routes }: { routes: RouteObject[] }) => {
    return (
        <RouterFragment>
            <Routes>
                {routes.map((item, index) => {
                    return (
                        <Route
                            path={item.path}
                            element={item.element}
                            key={index}
                        ></Route>
                    );
                })}
            </Routes>
        </RouterFragment>
    );
};
